// import { desktopCapturer } from 'electron';

const EventEmitter = require('events');
const peer = new EventEmitter();
const { ipcRenderer } = require('electron');

// 暂时实现本地监听
// peer.on('robot', (type, data) => {
//   console.log(type, data);
//   if (type === 'mouse') {
//     data.screen = {
//       width: window.screen.width,
//       height: window.screen.height,
//     };
//   }
//   ipcRenderer.send('robot', type, data);
// });

//发送rtc请求，第一次握手
const pc = new window.RTCPeerConnection({})
async function createOffer(){
  const offer = await pc.createOffer({
    offerToReceiveAudio:false,
    offerToReceiveVideo:true
  })
  await pc.setLocalDescription(offer)
  console.log('pc offer',JSON.stringify(offer))
  return pc.localDescription
}
createOffer()

//响应的SDP,传输到客户端，第三次握手
async function setRomote(e){
  await pc.setRemoteDescription(answer)
}
window.setRomote = setRomote
pc.onaddstream = function(e){
  console.log('addstream',e)
  peer.emit('add-stream',stream)
}
module.exports = peer;
